import { getSearchInfo, getSalesList, getSalesPrice } from "@/services";
let state = {
  searchList: [], //搜索列表
};
let mutations = {
  //搜索列表
  updateSearchList(state, payload) {
    state.searchList = payload;
    console.log(state.searchList);
  },
  //销量列表
  updateSales(state, payload) {
    state.searchList = payload;
    console.log(state.searchList);
  },
  //价格列表
  updatePrice(state, payload) {
    state.searchList = payload;
    console.log(state.searchList);
  },
};

let actions = {
  //搜索列表
  async getSearchInfo({ commit }, payload) {
    let res = await getSearchInfo({
      current: 1,
      prodName: payload,
      size: 10,
      sort: 0,
    });
    // console.log(res.records); 
    commit("updateSearchList", res.records);
  },
  //销量
  async getSalesList({ commit }, payload) {
    let res = await getSalesList({
      current: 1,
      prodName: payload,
      size: 10,
      sort: 1,
    });
    // console.log(res.records+'111');
    commit("updateSales", res.records);
  },
  //价格
  async getSalesPrice({ commit }, payload) {
    let res = await getSalesPrice({
      current: 1,
      prodName:payload,
      size: 10,
      sort: 2,
    });
    // console.log(res.records+'111');
    commit("updatePrice", res.records);
  },
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
